<?php
namespace App\Library\System;

use Zend\Db\Sql\Where;

abstract class Model extends App
{

    /**
     * Integrate data to object as properties
     *
     * @param $data
     */
    public function add($data)
    {
        foreach ($data as $key => $value) {
            $this->$key = $value;
        }
    }

    // Fetch array with query return no row such as Insert, Delete command
    public function non($sql)
    {
        $this->db->run($sql, 0);
    }

    // Fetch only one result such as Select command return one row
    public function one($sql)
    {
        return $this->db->run($sql, 1);
    }

    // Fetch and return multi-rows
    public function more($sql)
    {
        return $this->db->run($sql, 2);
    }

    // Build Select Command
    public function select()
    {
        return $this->db->sql->select();
    }

    // Build Insert Command
    public function insert()
    {
        return $this->db->sql->insert();
    }

    // Build Update Command
    public function update()
    {
        return $this->db->sql->update();
    }

    // Build Delete Command
    public function delete()
    {
        return $this->db->sql->delete();
    }

    public function where()
    {
        return new Where();
    }

    public function debug($variable)
    {
        Process::debug($variable);
    }
}